#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float32.hpp"


class NodeTe3 : public rclcpp::Node
{
private:
    // 声名定时器指针
    rclcpp::TimerBase::SharedPtr timer_;
    // 声明话题发布者指针
    rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr fabuzhe;
    //
    void timer_callback()
    {
        std_msgs::msg::Float32 msg;
        msg.data=1.0;
        RCLCPP_INFO(this->get_logger(), "ji ni tai mei: %f", msg.data);
        fabuzhe->publish(msg);//赋值完成，发布信息
    }

public:
    NodeTe3(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "%s节点已经启动.", name.c_str());
        // 创建发布者
        fabuzhe= this->create_publisher<std_msgs::msg::Float32>("ikun_receive", 10);
        // 创建定时器，250ms为周期，定时发布
        timer_= this->create_wall_timer(std::chrono::milliseconds(250), std::bind(&NodeTe::timer_callback, this));
    }

};


int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    /*创建对应节点的共享指针对象*/
    auto node = std::make_shared<NodeTe3>("node_te3");
    /* 运行节点，并检测退出信号*/
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}